package main

func hIndex(citations []int) int {
	// count[i] 表示引用数大于等于 i+1 的文章数
	count := make([]int, len(citations))
	for _, v := range citations {
		for i := 1; i <= v && i-1 < len(count); i++ {
			count[i-1]++
		}
	}
	for i := len(count) - 1; i >= 0; i-- {
		if count[i] >= i+1 {
			return i+1
		}
	}
	return 0
}

func main() {
	ret := hIndex([]int{1, 3, 1})
	println(ret)
}
